//
//  DetailActivityViewController.m
//  UI14_豆瓣电影更新版
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "DetailActivityViewController.h"
#import "UIImageView+WebCache.h"
#import "dataBaseHandle.h"
@interface DetailActivityViewController ()

@end

@implementation DetailActivityViewController
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}
- (void)dealloc {
    
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    // 标题
    self.navigationItem.title = _str;
    UIImage *img = [UIImage imageNamed:@"btn_nav_back@2x.png"];
    img = [img imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:img style:UIBarButtonItemStylePlain target:self action:@selector(itemAction:)];
    self.navigationItem.leftBarButtonItem = item;
    [item release];
    
    UIImage *img2 = [UIImage imageNamed:@"btn_nav_share@2x.png"];
    img2 = [img2 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithImage:img2 style:UIBarButtonItemStylePlain target:self action:@selector(itemAction2:)];
    self.navigationItem.rightBarButtonItem = item2;
    [item2 release];
    
    [self handel];
    
}
// 左item
- (void)itemAction:(UIBarButtonItem *)item {
    [self.navigationController popViewControllerAnimated:YES];

}
// 右item
- (void)itemAction2:(UIBarButtonItem *)item {
    
    NSArray *arr = [[dataBaseHandle sharedDataBaseHandle] selectModel];
    
    if ([arr containsObject:_model.title]) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"该活动已经被收藏过" preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        [alert addAction:action];
        [self presentViewController:alert animated:YES completion:^{
            
        }];

        
    }else{
        [[dataBaseHandle sharedDataBaseHandle] insertModel:_model];
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"收藏成功" preferredStyle:UIAlertControllerStyleAlert];
        [self presentViewController:alert animated:YES completion:^{
            
        }];
        [self performSelector:@selector(dismissAlert) withObject:nil afterDelay:1.5];
    
    }

}
- (void)dismissAlert {
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}
- (void)handel {
    UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 49)];
//    scroll.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:scroll];
    [scroll release];
    scroll.contentSize = CGSizeMake(0, self.view.frame.size.height * 2);
    UILabel *namelabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, self.view.frame.size.width - 40, 40)];
    [scroll addSubview:namelabel];
    namelabel.text = _model.title;
    namelabel.font = [UIFont systemFontOfSize:25];
    [namelabel release];
    
    UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(20, 80, 120, 180)];
    [scroll addSubview:img];
    NSString *str = _model.image;
    [img sd_setImageWithURL:[NSURL URLWithString:str]];
    // 小label
    UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(20, 270, 200, 30)];
    [scroll addSubview:lab];
    lab.text = @"活动介绍";
    lab.font = [UIFont systemFontOfSize:25];
    [lab release];
    // 大的label
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 300, self.view.frame.size.width - 40, self.view.frame.size.height - 300 + self.view.frame.size.height)];
    [scroll addSubview:label];
    
    label.text = _model.content;
    label.numberOfLines = 60;
    [label release];
    // 时间图标
    UIImageView *img1 = [[UIImageView alloc] initWithFrame:CGRectMake(150, 80, 30, 30)];
    img1.image = [UIImage imageNamed:@"icon_date_blue@2x.png"];
    [scroll addSubview:img1];
    [img1 release];
    // 时间
    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(180, 80, self.view.frame.size.width - 180, 30)];
    NSString *str2 = _model.begin_time;
    NSString *str3 = _model.end_time;
    NSString *newStr2 = [str2 substringWithRange:NSMakeRange(5, 11)];
    NSString *newStr3 = [str3 substringWithRange:NSMakeRange(5, 11)];
    NSString *str4 = [NSString stringWithFormat:@"%@ -- %@", newStr2, newStr3];
    label1.text = str4;
    [scroll addSubview:label1];
    [label1 release];
    // 地点图标
    UIImageView *img2 = [[UIImageView alloc] initWithFrame:CGRectMake(150, 115, 30, 30)];
    [scroll addSubview:img2];
    img2.image = [UIImage imageNamed:@"icon_sponsor_blue@2x.png"];
    [img2 release];
    // 地点
    UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(180, 115, self.view.frame.size.width - 180, 30)];
    [scroll addSubview:label2];
    id dic = _model.owner;
    label2.text = dic[@"name"];
    [label2 release];
    
    // 类型图标
    UIImageView *img3 = [[UIImageView alloc] initWithFrame:CGRectMake(150, 150, 30, 30)];
    img3.image = [UIImage imageNamed:@"icon_catalog_blue@2x.png"];
    [scroll addSubview:img3];
    [img3 release];
    // 类型
    UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(180, 150, self.view.frame.size.width - 180, 30)];
    [scroll addSubview:label3];
    label3.text = _model.category_name;
    [label3 release];
    // 地址图标
    UIImageView *img4 = [[UIImageView alloc] initWithFrame:CGRectMake(150, 185, 30, 30)];
    img4.image = [UIImage imageNamed:@"icon_spot_blue@2x.png"];
    [scroll addSubview:img4];
    [img4 release];
    // 地址
    UILabel *label4 = [[UILabel alloc] initWithFrame:CGRectMake(180, 180, self.view.frame.size.width - 180, 60)];
    label4.text = _model.address;
    [scroll addSubview:label4];
    label4.numberOfLines = 2;
    [label4 release];
        
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
